package com.rd.student.jiaji.class3.wangyanbo.exam;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) throws Exception {
        score();
    }

    public static void score() throws Exception {
        Boolean b = true;
        BufferedReader reader = new BufferedReader(new FileReader("Student.txt"));
        BufferedWriter writer = new BufferedWriter(new FileWriter("Student.txt"));
        String line = null;
        do {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入学生姓名:");
            String name = scanner.nextLine();
            System.out.println("语文成绩:");
            int Cscore = scanner.nextInt();
            System.out.println("数学成绩:");
            int Mscore = scanner.nextInt();

            int sum = Cscore + Mscore;
            ArrayList<String> list = new ArrayList();
            list.add(name);
            list.add(Cscore + "");
            list.add(Mscore + "");
            list.add(sum + "");

            if (line == null) {
                writer.write("姓名 语文成绩 数学成绩 总分");
                line="1";
            }

            writer.write("\n");


            for (Object o : list) {

                writer.write((String) o + " ");
            }
            System.out.println("输入2退出输入任意数字继续");
            int a = scanner.nextInt();
            if (a == 2) {
                b = false;
            }
        } while (b);
        reader.close();
        writer.close();

    }
}
